//
//  LGStatusCell.swift
//  LGWeibo
//
//  Created by 李更 on 8/14/16.
//  Copyright © 2016 itcast. All rights reserved.
//

import UIKit
import SnapKit
class LGStatusCell: UITableViewCell {
    
    var bottomViewTopconstraint : Constraint?
    
    
    //创建一个model供外界使用
    var statusViewModel : LGStatusViewModel?{
        didSet{
            
            OriginalView.StatusViewModel = statusViewModel
            //转发微博
            //卸载约束
            bottomViewTopconstraint?.uninstall()
            if statusViewModel?.statusModel?.retweeted_status == nil {
                StatusBottomView.snp_updateConstraints(closure: { (make) in
                   bottomViewTopconstraint = make.top.equalTo(OriginalView.snp_bottom).constraint
                })
                RetweetView.hidden = true
                
            }else{
                
                RetweetView.StatusViewModel = statusViewModel
                StatusBottomView.snp_updateConstraints(closure: { (make) in
                   bottomViewTopconstraint =  make.top.equalTo(RetweetView.snp_bottom).constraint
                })
                RetweetView.hidden = false
            }
           
        }
    }
  
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        backgroundColor = RandomColor()
        //添加控件
        contentView.addSubview(OriginalView)
        contentView.addSubview(RetweetView)
        contentView.addSubview(StatusBottomView)
        
        //添加约束
        //01
        OriginalView.snp_makeConstraints { (make) in
            make.leading.top.trailing.equalTo(contentView)
        }
        //02
        RetweetView.snp_makeConstraints { (make) in
            make.leading.trailing.equalTo(contentView)
            make.top.equalTo(OriginalView.snp_bottom)
        }
        //03
        StatusBottomView.snp_makeConstraints { (make) in
            make.leading.trailing.equalTo(contentView)
            bottomViewTopconstraint = make.top.equalTo(RetweetView.snp_bottom).constraint
            make.height.equalTo(35)
        }
        
        contentView.snp_makeConstraints { (make) in
            make.trailing.leading.top.equalTo(self)
            make.bottom.equalTo(StatusBottomView)
        }
    }
 
    //懒加载原创微博控件
    //原创微博
    private var OriginalView : LGStatusOriginalView = LGStatusOriginalView ()
    //转发微博
    private var RetweetView : LGStatusRetweetView = LGStatusRetweetView()
    //底部
    private var StatusBottomView : LGStatusBottomView = LGStatusBottomView()
   

}
